package com.lcu.bos.service.impl;

import com.lcu.bos.dao.IStaffDao;
import com.lcu.bos.modle.PageBean;
import com.lcu.bos.modle.Staff;
import com.lcu.bos.service.IStaffService;
import com.lcu.bos.service.base.BaseServiceImpl;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
@Service
@Transactional
public class StaffServiceImpl extends BaseServiceImpl<Staff> implements IStaffService {
    @Autowired
    private IStaffDao staffDao;
    @Override
    public void save(Staff entity) {
        staffDao.save(entity);
    }

    @Override
    public void delete(Staff entity) {
        staffDao.delete(entity);
    }

    @Override
    public void update(Staff entity) {
        staffDao.update(entity);
    }

    @Override
    public Staff find(Serializable id) {
        return staffDao.find(id);
    }

    @Override
    public List<Staff> findAll() {
        return staffDao.findAll();
    }

    @Override
    public void pageQuery(PageBean<Staff> pb) {
        staffDao.pageQuery(pb);
    }

    @Override
    public void deteteBatch(String ids) {
        String hql="UPDATE Staff SET deltag=  ? where id = ?";
        //拆分ids
        String[] idsArr=ids.split(",");
        for (String id:idsArr){
            //批量的删除
            staffDao.executeUpdate(hql,"1",id);
        }
    }

    @Override
    public List<Staff> findAllWithNoDelete() {
        //使用离线查询对象
        DetachedCriteria dc=DetachedCriteria.forClass(Staff.class);
        dc.add(Restrictions.eq("deltag","0"));

        return staffDao.findAllbyDetachedCriteria(dc);
    }
}
